import '../base/composed_player.dart';
import 'package:rapid_kit/rapid_kit.dart';

/// 探鸽公共页面 - 播放相关
class LocalReplayPlayer extends ComposedPlayer {
  final Pipe _pipe;

  // all replay stream use same channel to transfer video data
  // so we only need one stream to replay all video data
  late LocalReplayStream _stream;

  LocalReplayPlayer(this._pipe) : super();

  @override
  void prepare(int cameraCount) {
    super.prepare(cameraCount);

    _stream = LocalReplayStream.create(_pipe);
    playerOfCamera0.prepare(_stream.provider()!);
    if (cameraCount >= 2) playerOfCamera1?.prepare(_stream.provider(cameraIndex: 1)!);
    if (cameraCount == 3) playerOfCamera2?.prepare(_stream.provider(cameraIndex: 2)!);

    // if you have more than 3 cameras, you can add more player here
  }

  @override
  void resume() {
    super.resume();
    _stream.start();
  }

  @override
  void pause() {
    super.pause();
    _stream.stop();
  }

  @override
  void dispose() {
    super.dispose();
    _stream.destroy();
  }

  void speed(LocalReplaySpeed speed) {
    _stream.setSpeed(speed);
  }
}
